Skip to content

feat: Porting PadLeft and PadRight from C##46

Open
gavinbm wants to merge 9 commits intomicrosoft:mainfrom
gavinbm:padding-funcs
Open

feat: Porting PadLeft and PadRight from C##46
gavinbm wants to merge 9 commits intomicrosoft:mainfrom
gavinbm:padding-funcs

Conversation

@gavinbm
Copy link
Copy Markdown

@gavinbm gavinbm commented Jun 26, 2024

This PR adds support for calling the single argument version of PadLeft and PadRight to the Text functions. These functions take as arguments the strings they're operating on and the number of spaces to add as padding. Also have some basic tests, feedback on those is very much appreciated as I may be missing some things there.

C# docs for functions this PR includes:
https://learn.microsoft.com/en-us/dotnet/api/system.string.padleft?view=net-8.0#system-string-padleft(system-int32)
https://learn.microsoft.com/en-us/dotnet/api/system.string.padright?view=net-8.0#system-string-padright(system-int32)

@gavinbm
Copy link
Copy Markdown
Author

gavinbm commented Jun 26, 2024

@gavinbm please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

shonk-msft

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

@shonk-msft shonk-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description is a bit misleading. The number of characters added is just enough to get to the specified length, not the number specified in the second argument.

@@ -238,6 +238,14 @@ Text.Replace("ABC", "X", s)
Text.Replace("ABC", "B", "X")
Text.Replace("ABACDAE", "A", "!!")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be multiple kinds of test cases:

  • Test with the named globals to ensure that errors are produced on bad input types, conversions are inserted where needed (eg, using u2 for the length), arity is handled correctly.
  • Test with special values to ensure that reduction happens as expected (once ReduceCore is implemented). Use enough cases that all the code in ReduceCore and in the ExecXxx methods is covered.
  • Tests that use "opt" types in slots that lift over opt. Eg, tests that use qi8 and something like qu2 for the length.

Text.Replace(s, s, s)

Text.Replace(s, "", s)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests aren't needed since they just duplicate what is above.
Tests here should be for lifting over sequence.
Also, we should add tensor based lifting tests, not just sequence.

Text.Replace(N, "A", "B")
Text.Replace("A", N, "B")
Text.Replace("ABC", Wrap("B"), N)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also have:

  • Tests for lifting.
  • Tests of cases that aren't reduced during binding (once ReduceCore is implemented). That's the purpose of using Wrap.

@askwenhan askwenhan requested a review from shonk-msft June 27, 2024 20:41
Copy link
Copy Markdown
Contributor

@shonk-msft shonk-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to run the tests and update the test baselines appropriately. Also see the comments about the types of tests needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants